<?php

namespace App\Component\Blade;

use Teeb\Base\Application;

class BladeManager
{
    protected $app;

    protected $blade;
    protected $viewpath;         // your view file path, it's an array
    protected $cachepath;     // compiled file path
    public function __construct(Application $app)
    {
        //var_dump($a);
        $this->app = $app; //绑定app对象
        $this->viewpath = [$app->viewPath().'/bladeview/']; //设置模板路径
        $this->cachepath = $app->runtimePath().'/bladecache/'; //设置缓存路径
        foreach ($this->viewpath as $key => $value) {
            //app()->log->warning($value);
            if (!file_exists($value)) {
                mkdir($value, 0777, true);
            }            
        }

        if (!file_exists($this->cachepath)) {
            mkdir($this->cachepath, 0777, true);
        }
        //如果路径不存在,创建文件夹,给777权限 可写可读
        require_once($app->basePath().'/library/blade/src/Blade.class.php'); //引入blade类主接口文件
        $this->blade = new \Blade($this->viewpath,$this->cachepath,$app);
        //初始化新的Blade对象,并且传入构造初始化模板参数
        //return $this->blade;
    }
    public function __call($method, $param)
    {
        return call_user_func_array(array($this->blade, $method), $param);  
    }
}